package com.evenmo.mapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.evenmo.pojo.BigData;

/**
 * 大批量测试数据接口
 * @author Administrator
 *
 */
public interface BigDataMapper {
	@Select("select * from test_bigdata where 1=1")//and name concat(concat('%',#{name}),'%')
	public List<BigData> queryBigDatas2(BigData bigdata);
	
	@Select("select * from test_bigdata")
	public List<BigData> queryBigDatas();
	@Select("select count(id) from test_bigdata  where 1=1")
	public Long queryBigDatas2_COUNT();
	@Insert("insert into test_bigdata(name,hobby) values(#{name,jdbcType=VARCHAR},#{hobby,jdbcType=VARCHAR})")
	public int insertDatas(BigData data);
	//注解方式的foreach批量插入--mysql
	@Insert(value= {"<script>",
			 "insert into test_bigdata(name, hobby) values ",
			 "<foreach collection='dataList' item='item' index='index' separator=','>",
			 "(#{item.name,jdbcType=VARCHAR}, #{item.hobby,jdbcType=VARCHAR})",
			 "</foreach>",
			 "</script>"})
	public int insertDatasQuickly(@Param(value="dataList")List<BigData> dataList);
	
//	//传入list时
//	@Select(value= {
//			"<script>",
//			 "select * from test_bigdata where id in ",
//			 "<foreach collection='dataList' item='item' index='index' open='(' close=')' separator=','>",
//			 "#{item,jdbcType=VARCHAR}",
//			 "</foreach>",
//			 "</script>"	
//	})
//	public List<BigData> queryBigDatasByIds(@Param(value="dataList") A<Integer> dataList);
//	
	
	@Select(value= {
			"<script>",
			 "select * from test_bigdata where id in (#{ids})",
			 "</script>"	
	})
	
	public List<BigData> queryBigDatasByIds(Map<String,Object> map);
	
	//批量更新
	@Update(value= {
			"<script>",
			"update test_bigdata set ",
			"name=",
			"case id when id then concat('testname',id) end,",
			"hobby=",
			"case id when id then concat('hobby',id) end ",
			"where id in ",
			"<foreach collection='list' item='item' index='index' close=')' open='(' separator=','>",
			"#{item.id,jdbcType=INTEGER}",
			"</foreach>",
			"</script>"
			
	})
	public int updateBatch(List<BigData> list);
	
	@Select("select * from test_bigdata where name=#{data.name,jdbcType=VARCHAR}")
	public List<BigData> querydatatest(@Param("data")BigData data);
}
 